//导入axios
import axios from 'axios'

//实例化axios对象
var service = axios.create({
    timeout: 30 * 1000,//设置超时时间
    baseURL: '/api'//请求地址的基准路径
})

//设置请求拦截
service.interceptors.request.use(
    (config) => {
        return config;
    }, (error) => {
        return Promise.reject(error);
    })
//设置响应拦截
service.interceptors.request.use(
    (res) => {
        return res;
    }, (error) => {
        if (error.response.status == 401) {
            console.log('身份认证过期，请重新登录！')
        } else if (error.response.status == 404) {
            console.log('访问路径有误！')
        } else if (error.response.status == 500) {
            console.log('服务器问题')
        }
    }
)
export default service;